<template>
  <ul>
    <!--循环遍历指令-->
    <li v-for="name in arr">{{name}}</li>
  </ul>
  <table border="1">
    <caption>员工列表</caption>
    <tr><th>编号</th><th>姓名</th><th>工资</th><th>工作</th><th>操作</th></tr>
    <tr v-for="(emp,i) in empArr">
      <td>{{i+1}}</td><td>{{emp.name}}</td><td>{{emp.salary}}</td><td>{{emp.job}}</td>
      <td><input type="button" value="删除" @click="del(i)"></td>
    </tr>
  </table>
</template>
<script setup>
  import {ref} from "vue";
  const del = (i)=>{
    if (confirm('您确认要删除此员工吗?')){
      //从数组中删除
      empArr.value.splice(i,1);
    }
  }

  const arr = ref(["刘备","关羽","张飞"]);
  const empArr = ref([{name:"刘备",salary:5000,job:"销售"},
    {name:"关羽",salary:7000,job:"人事"},
    {name:"张飞",salary:9000,job:"程序员"}]);
</script>

<style scoped>

</style>